package com.epalmpay.service.app.impl;

import com.epalmpay.dto.appshop.ShopIndexOutDTO;
import com.epalmpay.dto.appshop.ShopTradeStatisOutDTO;
import com.epalmpay.dto.appshop.TradeDrawOutDTO;
import com.epalmpay.dto.bonus.BonusRuleOutDTO;
import com.epalmpay.dto.bonus.BonusVerifyLogOutDTO;
import com.epalmpay.entity.*;
import com.epalmpay.entity.profit.Profit;
import com.epalmpay.entity.profit.ProfitShopDayDetail;
import com.epalmpay.entity.profit.ProfitShopMonth;
import com.epalmpay.enumdef.ActivityEnum;
import com.epalmpay.enumdef.BizEnum;
import com.epalmpay.enumdef.CommonEnum;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.mapper.*;
import com.epalmpay.mapper.profit.ProfitShopDayDetailMapper;
import com.epalmpay.mapper.profit.ProfitShopMonthMapper;
import com.epalmpay.payplat.IPayAPI;
import com.epalmpay.payplat.MerchantWithsDraw;
import com.epalmpay.payplat.PayBalanceQuery;
import com.epalmpay.payplat.result.PayBalanceResult;
import com.epalmpay.payplat.result.PayResult;
import com.epalmpay.payplat.result.PayTransferResult;
import com.epalmpay.service.app.IAppShopService;
import com.epalmpay.service.weixin.IWalletService;
import com.epalmpay.status.Rescode;
import com.epalmpay.util.*;
import com.epalmpay.util.Response;
import com.epalmpay.util.payplat.UtilFun;
import org.apache.ibatis.jdbc.Null;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

import static com.epalmpay.util.DateUtil.sdfMonth;

/**
 * Created by Administrator on 2018/2/9.
 */
@Service("appShopService")
public class IAppShopServiceImpl implements IAppShopService {

    @Resource
    private OrderGoodMapper orderGoodMapper;

    @Resource
    private ShopMapper shopMapper;

    @Resource
    private TradeOfflineMapper tradeOfflineMapper;

    @Resource
    private TradeWithdrawMapper tradeWithdrawMapper;

    @Resource
    private BonusVerifyShopMapper bonusVerifyShopMapper;

    @Resource
    private BonusSendLogMapper bonusSendLogMapper;

    @Resource
    private BonusVerifyLogMapper bonusVerifyLogMapper;

    @Resource
    private BonusShopSettleLogMapper bonusShopSettleLogMapper;

    @Resource
    private MallGoodCommentMapper mallGoodCommentMapper;

    @Resource
    private ActivityUnroutineMapper activityUnroutineMapper;

    @Resource
    private ActivityUnroutineRuleMapper activityUnroutineRuleMapper;

    @Resource
    private ActivityUnroutineShopPlusMapper activityUnroutineShopPlusMapper;

    @Resource
    private RedpackageMapper redpackageMapper;

    @Resource
    private CouponMapper couponMapper;

    @Resource
    private OrderServiceGoodDetailMapper orderServiceGoodDetailMapper;
    
    @Resource
	private IWalletService walletService;

    @Resource
    private StatisShopMapper statisShopMapper;

    @Resource
    private CouponUserMapper couponUserMapper;
    @Resource
    private RedpackageUserMapper redpackageUserMapper;

    @Resource
    private BonusSendRuleMapper bonusSendRuleMapper;

    @Resource
    private BonusVerifyRuleMapper bonusVerifyRuleMapper;

    @Resource
    private ProfitShopDayDetailMapper profitShopDayDetailMapper;

    @Resource
    private ProfitShopMonthMapper profitShopMonthMapper;

    @Resource
    private MemberMapper memberMapper;

    @Resource
    private ProfitMapper profitMapper;


    @Override
    public Response firstPage(String shopId) throws ApplicationException {
        Map<String, Object> map = new HashMap<String, Object>();

        Shop shop = shopMapper.selectShopDataAndGroupId(Long.parseLong(shopId));

        if (shop == null) {
            return Response.getError("商户信息不存在");
        }
        ShopIndexOutDTO shopIndexOutDTO = shopMapper.firstPage(Long.parseLong(shopId));
        ShopIndexOutDTO shopIndexOutDTO2 = shopMapper.firstPage2(Long.parseLong(shopId));
        ShopIndexOutDTO shopIndexOutDTO3 = shopMapper.firstPage3(Long.parseLong(shopId));
        ShopIndexOutDTO shopIndexOutDTO4= shopMapper.firstPage4(Long.parseLong(shopId));
        ShopIndexOutDTO shopIndexOutDTO5 = shopMapper.firstPage5(Long.parseLong(shopId));
        ShopIndexOutDTO shopIndexOutDTO6 = shopMapper.firstPage6(Long.parseLong(shopId));
        ShopIndexOutDTO shopIndexOutDTO7= shopMapper.firstPage7(Long.parseLong(shopId));
        ShopIndexOutDTO shopIndexOutDTO8 = shopMapper.firstPage8(Long.parseLong(shopId));
        ShopIndexOutDTO shopIndexOutDTO9 = shopMapper.firstPage9(Long.parseLong(shopId));

        //组装返回动态的数据返回前端
        List<Map<String,Object>> shopDataList = new ArrayList<Map<String, Object>>();
        Map<String,Object> det = new HashMap<>();
        det.put("id",1);
        det.put("name","交易总额");
        det.put("type","1");
        det.put("value",String.valueOf(shopIndexOutDTO.getRealAmount()));
        shopDataList.add(det);

        Map<String,Object> det2 = new HashMap<>();
        det2.put("id",2);
        det2.put("name","核销券码结算金额");
        det2.put("type","1");
        det2.put("value",String.valueOf(shopIndexOutDTO.getSettingPrice()));
        shopDataList.add(det2);

        Map<String,Object> det3 = new HashMap<>();
        det3.put("id",3);
        det3.put("name","核销券码金额");
        det3.put("type","1");
        det3.put("value",String.valueOf(shopIndexOutDTO.getPrice()));
        shopDataList.add(det3);

        Map<String,Object> det4 = new HashMap<>();
        det4.put("id",4);
        det4.put("name","券码核销张数");
        det4.put("type","2");
        det4.put("value",shopIndexOutDTO2.getServicegoodVeriftyCount().toString());
        shopDataList.add(det4);

        Map<String,Object> det5 = new HashMap<>();
        det5.put("id",5);
        det5.put("name","积分抵扣总金额");
        det5.put("type","1");
        det5.put("value",String.valueOf(shopIndexOutDTO2.getBonusAmount()));
        shopDataList.add(det5);

        Map<String,Object> det6 = new HashMap<>();
        det6.put("id",6);
        det6.put("name","核销积分数");
        det6.put("type","2");
        det6.put("value",shopIndexOutDTO2.getBonusNumber().toString());
        shopDataList.add(det6);

        Map<String,Object> det7 = new HashMap<>();
        det7.put("id",7);
        det7.put("name","发放积分数");
        det7.put("type","2");
        det7.put("value",shopIndexOutDTO2.getSendBonusNumber().toString());
        shopDataList.add(det7);

        Map<String,Object> det8 = new HashMap<>();
        det8.put("id",8);
        det8.put("name","优惠券抵扣金额");
        det8.put("type","1");
        det8.put("value",String.valueOf(shopIndexOutDTO3.getDiscountAmount()));
        shopDataList.add(det8);

        Map<String,Object> det9 = new HashMap<>();
        det9.put("id",9);
        det9.put("name","优惠券核销笔数");
        det9.put("type","2");
        det9.put("value",shopIndexOutDTO3.getVerifyCouponNumber().toString());
        shopDataList.add(det9);

        Map<String,Object> det10 = new HashMap<>();
        det10.put("id",10);
        det10.put("name","发放优惠券数");
        det10.put("type","2");
        det10.put("value",shopIndexOutDTO3.getCouponSendNumber().toString());
        shopDataList.add(det10);

        Map<String,Object> det11 = new HashMap<>();
        det11.put("id",11);
        det11.put("name","交易总人数");
        det11.put("type","2");
        det11.put("value",String.valueOf(shopIndexOutDTO3.getTradeMemberCount()+shopIndexOutDTO4.getNoMemberCount()));
        shopDataList.add(det11);

        Map<String,Object> det12 = new HashMap<>();
        det12.put("id",12);
        det12.put("name","新会员交易人数");
        det12.put("type","2");
        det12.put("value",shopIndexOutDTO4.getNewMemberCount().toString());
        shopDataList.add(det12);

        Map<String,Object> det13 = new HashMap<>();
        det13.put("id",13);
        det13.put("name","老会员交易人数");
        det13.put("type","2");
        det13.put("value",String.valueOf(shopIndexOutDTO3.getTradeMemberCount()-shopIndexOutDTO4.getNewMemberCount()));
        shopDataList.add(det13);

        Map<String,Object> det14 = new HashMap<>();
        det14.put("id",14);
        det14.put("name","待发货订单");
        det14.put("type","2");
        det14.put("value",shopIndexOutDTO4.getWaitOrderCount().toString());
        shopDataList.add(det14);

        Map<String,Object> det15 = new HashMap<>();
        det15.put("id",15);
        det15.put("name","待售后订单");
        det15.put("type","2");
        det15.put("value",shopIndexOutDTO4.getAfterSaleOrderCount().toString());
        shopDataList.add(det15);

        Map<String,Object> det16 = new HashMap<>();
        det16.put("id",16);
        det16.put("name","商城订单金额");
        det16.put("type","1");
        det16.put("value",String.valueOf(shopIndexOutDTO5.getGoodAmount()));
        shopDataList.add(det16);

        Map<String,Object> det17 = new HashMap<>();
        det17.put("id",17);
        det17.put("name","商城在售商品数");
        det17.put("type","2");
        det17.put("value",shopIndexOutDTO5.getOnSaleCount().toString());
        shopDataList.add(det17);

        Map<String,Object> det18 = new HashMap<>();
        det18.put("id",18);
        det18.put("name","商城商品客单价");
        det18.put("type","1");
        if(shopIndexOutDTO5.getGoodAmount()==0 ||shopIndexOutDTO5.getGoodNumber()==0){
            det18.put("value","0");
        }else{
            det18.put("value",String.valueOf(shopIndexOutDTO5.getGoodAmount()/shopIndexOutDTO5.getGoodNumber()));
        }
        shopDataList.add(det18);

        Map<String,Object> det19 = new HashMap<>();
        det19.put("id",19);
        det19.put("name","交易客单价");
        det19.put("type","1");
        if(shopIndexOutDTO.getRealAmount()==0 || shopIndexOutDTO5.getTradeNumber()==0){

            det19.put("value","0");
        }else{
            det19.put("value",String.valueOf(shopIndexOutDTO.getRealAmount()/shopIndexOutDTO5.getTradeNumber()));
        }
        shopDataList.add(det19);

        Map<String,Object> det20 = new HashMap<>();
        det20.put("id",20);
        det20.put("name","微信收银");
        det20.put("type","1");
        det20.put("value",String.valueOf(shopIndexOutDTO6.getWxRealAmount()));
        shopDataList.add(det20);

        Map<String,Object> det21 = new HashMap<>();
        det21.put("id",21);
        det21.put("name","微信收银笔数");
        det21.put("type","2");
        det21.put("value",shopIndexOutDTO6.getWxCount().toString());
        shopDataList.add(det21);

        Map<String,Object> det22 = new HashMap<>();
        det22.put("id",22);
        det22.put("name","微信退款金额");
        det22.put("type","1");
        det22.put("value",String.valueOf(shopIndexOutDTO6.getWxRefundRealAmount()));
        shopDataList.add(det22);

        Map<String,Object> det23 = new HashMap<>();
        det23.put("id",23);
        det23.put("name","微信退款笔数");
        det23.put("type","2");
        det23.put("value",shopIndexOutDTO6.getWxRefundCount().toString());
        shopDataList.add(det23);

        Map<String,Object> det24 = new HashMap<>();
        det24.put("id",24);
        det24.put("name","支付宝收银");
        det24.put("type","1");
        det24.put("value",String.valueOf(shopIndexOutDTO7.getAliPayRealAmount()));
        shopDataList.add(det24);

        Map<String,Object> det25 = new HashMap<>();
        det25.put("id",25);
        det25.put("name","支付宝收银笔数");
        det25.put("type","2");
        det25.put("value",shopIndexOutDTO7.getAliPayCount().toString());
        shopDataList.add(det25);

        Map<String,Object> det26 = new HashMap<>();
        det26.put("id",26);
        det26.put("name","支付宝退款金额");
        det26.put("type","1");
        det26.put("value",String.valueOf(shopIndexOutDTO7.getAliPayRefundRealAmount()));
        shopDataList.add(det26);

        Map<String,Object> det27 = new HashMap<>();
        det27.put("id",27);
        det27.put("name","支付宝退款笔数");
        det27.put("type","2");
        det27.put("value",shopIndexOutDTO7.getAliPayRefundCount().toString());
        shopDataList.add(det27);

        Map<String,Object> det28 = new HashMap<>();
        det28.put("id",28);
        det28.put("name","刷卡收银");
        det28.put("type","1");
        det28.put("value",String.valueOf(shopIndexOutDTO8.getCardRealAmount()));
        shopDataList.add(det28);

        Map<String,Object> det29 = new HashMap<>();
        det29.put("id",29);
        det29.put("name","刷卡收银笔数");
        det29.put("type","2");
        det29.put("value",shopIndexOutDTO8.getCardCount().toString());
        shopDataList.add(det29);

        Map<String,Object> det30 = new HashMap<>();
        det30.put("id",30);
        det30.put("name","刷卡退款金额");
        det30.put("type","1");
        det30.put("value",String.valueOf(shopIndexOutDTO8.getCardRefundRealAmount()));
        shopDataList.add(det30);

        Map<String,Object> det31 = new HashMap<>();
        det31.put("id",31);
        det31.put("name","刷卡退款笔数");
        det31.put("type","2");
        det31.put("value",shopIndexOutDTO8.getCardRefundCount().toString());
        shopDataList.add(det31);

        Map<String,Object> det32 = new HashMap<>();
        det32.put("id",32);
        det32.put("name","钱包收银");
        det32.put("type","1");
        det32.put("value",String.valueOf(shopIndexOutDTO9.getWallerRealAmount()));
        shopDataList.add(det32);

        Map<String,Object> det33 = new HashMap<>();
        det33.put("id",33);
        det33.put("name","钱包收银笔数");
        det33.put("type","2");
        det33.put("value",shopIndexOutDTO9.getWallerCount().toString());
        shopDataList.add(det33);

        Map<String,Object> det34 = new HashMap<>();
        det34.put("id",34);
        det34.put("name","钱包退款金额");
        det34.put("type","1");
        det34.put("value",String.valueOf(shopIndexOutDTO9.getWallerRefundRealAmount()));
        shopDataList.add(det34);

        Map<String,Object> det35 = new HashMap<>();
        det35.put("id",35);
        det35.put("name","钱包退款笔数");
        det35.put("type","2");
        det35.put("value",shopIndexOutDTO9.getWallerCount().toString());
        shopDataList.add(det35);

        Map<String,Object> det36 = new HashMap<>();
        det36.put("id",36);
        det36.put("name","现金收银");
        det36.put("type","1");
        det36.put("value",String.valueOf(shopIndexOutDTO9.getCashRealAmount()));
        shopDataList.add(det36);

        Map<String,Object> det37 = new HashMap<>();
        det37.put("id",37);
        det37.put("name","退款总额");
        det37.put("type","1");
        det37.put("value",String.valueOf(shopIndexOutDTO9.getRefundAmount()));
        shopDataList.add(det37);

        Map<String,Object> det38 = new HashMap<>();
        det38.put("id",38);
        det38.put("name","非会员交易笔数");
        det38.put("type","2");
        det38.put("value",String.valueOf(shopIndexOutDTO9.getNoMemberCount()));
        shopDataList.add(det38);

        Map<String,Object> det39 = new HashMap<>();
        det39.put("id",39);
        det39.put("name","商城交易笔数");
        det39.put("type","2");
        det39.put("value",String.valueOf(shopIndexOutDTO9.getGoodNumber()));
        shopDataList.add(det39);

        map.put("shopDataList",shopDataList);

        Map<String,Object> param=new HashMap<String,Object>();
        param.put("shopId",Long.parseLong(shopId));
        param.put("start", 0);
        param.put("limit", 2);//取2行
        //门店参与中活动
        List<ActivityUnroutine> activityUnroutineList= activityUnroutineMapper.queryShopActivityList(param);
        List<Map<String,Object>> activityList = new ArrayList<Map<String, Object>>();
        for(ActivityUnroutine activityUnroutine:activityUnroutineList){
            Map<String,Object> detail = new HashMap<>();
            detail.put("activityId",activityUnroutine.getActivityId());
            detail.put("activityName",activityUnroutine.getActivityName());
            detail.put("startTime",activityUnroutine.getStartTime());
            detail.put("endTime",activityUnroutine.getEndTime());
            detail.put("sendType",activityUnroutine.getSendType());

            activityList.add(detail);
        }
        if(activityList.size()>0){
            map.put("activityList",activityList);
        }

        //门店参与优惠券
        Map<String,Object> param1=new HashMap<String,Object>();
        param1.put("shopId",Long.parseLong(shopId));
        param1.put("start", 0);
        param1.put("limit", 2);//取2行
        List<Coupon> coupons= couponMapper.queryCouponList(param1);
        List<Map<String,Object>> couponList = new ArrayList<Map<String, Object>>();
        for(Coupon coupon:coupons){
            Map<String,Object> couponDetail = new HashMap<>();
            couponDetail.put("couponId",coupon.getId());
            couponDetail.put("couponName",coupon.getName());
            couponDetail.put("faceValue",coupon.getValue());
            couponDetail.put("couponStatus",coupon.getStatus());
            if(coupon.getValidTimeType()==ActivityEnum.ValidTimeType.AfterGet.getType()){
                couponDetail.put("vaildTime","领取后"+coupon.getDays()+"天内有效");
            }else{
                couponDetail.put("vaildTime",coupon.getValidEndTime());
            }

            couponList.add(couponDetail);
        }
        if(couponList.size()>0){
            map.put("couponList",couponList);
        }

//        Shop shopInfo=shopMapper.selectShopInfo(Long.parseLong(shopId),shop.getGroupId());
//        String UserId=shopInfo.getShopGroupRelation().getPayMerchantCode()+"";
//        String GroupId=shopInfo.getGroup().getPayGroupCode();
//
//        Wallet wallet=walletService.selectShopWallet(UserId, GroupId, shopInfo.getUserId());
//        //此处余额需要查询支付平台
//        map.put("balance",wallet.getCanBalance());//余额
//        map.put("feeBalance",wallet.getCanBalanceLocked());//锁定金额

        //门店评分
        List<Map<String,Object>> scoreList = new ArrayList<Map<String, Object>>();
        MallGoodComment mallGoodComment = mallGoodCommentMapper.queryShopScoreData(Long.parseLong(shopId));
        Map<String,Object> detail = new HashMap<>();
        if(mallGoodComment !=null){
            Integer totalNumber = mallGoodComment.getOneNumber()+mallGoodComment.getTwoNumber()+mallGoodComment.getThreeNumber()+mallGoodComment.getFourNumber()+mallGoodComment.getFiveNumber();
            detail.put("totalNumber",totalNumber);
            if(mallGoodComment.getOneNumber()==0 && mallGoodComment.getTwoNumber()==0 && mallGoodComment.getThreeNumber()==0 &&
                    mallGoodComment.getFourNumber()==0 && mallGoodComment.getFiveNumber()==0){
                detail.put("oneScore",100);
            }else{
                if(mallGoodComment.getOneNumber()==0){
                    detail.put("oneScore",0);
                }else{
                    detail.put("oneScore",Float.parseFloat(String.format("%.2f", mallGoodComment.getOneNumber().floatValue()/totalNumber.floatValue()))*100);
                }
            }
            if(mallGoodComment.getOneNumber()==0 && mallGoodComment.getTwoNumber()==0 && mallGoodComment.getThreeNumber()==0 &&
                    mallGoodComment.getFourNumber()==0 && mallGoodComment.getFiveNumber()==0){
                detail.put("twoScore",100);
            }else{
                if(mallGoodComment.getTwoNumber()==0){
                    detail.put("twoScore",0);
                }else{
                    detail.put("twoScore",Float.parseFloat(String.format("%.2f", mallGoodComment.getTwoNumber().floatValue()/totalNumber.floatValue()))*100);
                }
            }

            if(mallGoodComment.getOneNumber()==0 && mallGoodComment.getTwoNumber()==0 && mallGoodComment.getThreeNumber()==0 &&
                    mallGoodComment.getFourNumber()==0 && mallGoodComment.getFiveNumber()==0){
                detail.put("threeScore",100);
            }else{
                if(mallGoodComment.getThreeNumber()==0){
                    detail.put("threeScore",0);
                }else{
                    detail.put("threeScore",Float.parseFloat(String.format("%.2f", mallGoodComment.getThreeNumber().floatValue()/totalNumber.floatValue()))*100);
                }
            }

            if(mallGoodComment.getOneNumber()==0 && mallGoodComment.getTwoNumber()==0 && mallGoodComment.getThreeNumber()==0 &&
                    mallGoodComment.getFourNumber()==0 && mallGoodComment.getFiveNumber()==0){
                detail.put("fourScore",100);
            }else{
                if(mallGoodComment.getFourNumber()==0){
                    detail.put("fourScore",0);
                }else{
                    detail.put("fourScore",Float.parseFloat(String.format("%.2f", mallGoodComment.getFourNumber().floatValue()/totalNumber.floatValue()))*100);
                }
            }

            if(mallGoodComment.getOneNumber()==0 && mallGoodComment.getTwoNumber()==0 && mallGoodComment.getThreeNumber()==0 &&
                    mallGoodComment.getFourNumber()==0 && mallGoodComment.getFiveNumber()==0){
                detail.put("fiveScore",100);
            }else{
                if(mallGoodComment.getFiveNumber()==0){
                    detail.put("fiveScore",0);
                }else{
                    detail.put("fiveScore",Float.parseFloat(String.format("%.2f", mallGoodComment.getFiveNumber().floatValue()/totalNumber.floatValue()))*100);
                }
            }
            if (totalNumber!=0) {

                int totalScore = 1 * mallGoodComment.getOneNumber() + 2 * mallGoodComment.getTwoNumber() + 3 * mallGoodComment.getThreeNumber() + 4 * mallGoodComment.getFourNumber() + 5 * mallGoodComment.getFiveNumber();
                float avgScore = (float) totalScore / (float) totalNumber;
                detail.put("avgScore", String.valueOf(avgScore));
            }else{
                detail.put("avgScore","5");
            }

            scoreList.add(detail);
        }else{
            detail.put("totalNumber",0);
            detail.put("oneScore",100);
            detail.put("twoScore",100);
            detail.put("threeScore",100);
            detail.put("foreScore",100);
            detail.put("fiveScore",100);
            detail.put("avgScore","5");
            scoreList.add(detail);
        }
        map.put("scoreList",scoreList);


        return Response.getSuccess(map);
    }

    @Override
    public Response simpleIndex(String shopId) throws ApplicationException {
        Map<String, Object> map = new HashMap<String, Object>();


        ShopIndexOutDTO shopIndexOutDTO = shopMapper.simpleIndex(Long.parseLong(shopId));
        if (shopIndexOutDTO == null) {
            return Response.getError("商户信息不存在");
        }
        map.put("yestOrderNum",shopIndexOutDTO.getYestOrderNum());
        map.put("todayOrderNum",shopIndexOutDTO.getTodayOrderNum());
        map.put("yestTradeAmount",shopIndexOutDTO.getYestTradeAmount());
        map.put("todayTradeAmount",shopIndexOutDTO.getTodayTradeAmount());
        map.put("yestBonusSendAmount",shopIndexOutDTO.getYestBonusSendAmount());
        map.put("veriftyBonusAmount",shopIndexOutDTO.getVeriftyBonusAmount());
        map.put("yestcouponSendNumber",shopIndexOutDTO.getYestcouponSendNumber());
        map.put("veriftyCouponNumber",shopIndexOutDTO.getVeriftyCouponNumber());
        return Response.getSuccess(map);
    }

    @Override
    public Response index(String shopId) throws ApplicationException {
        Map<String, Object> map = new HashMap<String, Object>();
        Shop shop = shopMapper.selectShopDataAndGroupId(Long.parseLong(shopId));
        if(shop ==null){
            return Response.getError("商户信息不存在");
        }
        map.put("bonusSum",shop.getBonusAmount());
        map.put("shopName",shop.getMerchantName());
        map.put("icon",shop.getIcon());
        map.put("gmtCreate",shop.getGmtCreate());
        map.put("groupId",shop.getGroupId());
        map.put("userId",shop.getUserId());

        Shop shopInfo=shopMapper.selectShopInfo(Long.parseLong(shopId),shop.getGroupId());

        String UserId=shopInfo.getShopGroupRelation().getPayMerchantCode()+"";

        String GroupId=shopInfo.getGroup().getPayGroupCode();
        Wallet wallet=walletService.selectShopWallet(UserId, GroupId, shopInfo.getUserId());
        //此处余额需要查询支付平台
		map.put("balance",wallet.getCanBalance());//余额
        map.put("feeBalance",wallet.getCanFreezeBalance());//锁定金额
        return Response.getSuccess(map);
    }

    @Override
    public Response shopBalance(String shopId) throws ApplicationException {
        Map<String, Object> map = new HashMap<String, Object>();
        Shop shop = shopMapper.selectShopDataAndGroupId(Long.parseLong(shopId));
        if(shop ==null){
            return Response.getError("商户信息不存在");
        }

        Shop shopInfo=shopMapper.selectShopInfo(Long.parseLong(shopId),shop.getGroupId());
        String UserId=shopInfo.getShopGroupRelation().getPayMerchantCode()+"";
        String GroupId=shopInfo.getGroup().getPayGroupCode();
        
        Wallet wallet=walletService.selectShopWallet(UserId, GroupId, shopInfo.getUserId());
        //此处余额需要查询支付平台
		map.put("balance",wallet.getCanBalance());//余额
        map.put("feeBalance",wallet.getCanFreezeBalance());//冻结金额
        map.put("lockBalance",wallet.getCanBalanceLocked());//锁定金额


        //查询最新的钱包交易信息
        Integer payType = BizEnum.PaymentType.Wallet.getType();
        TradeOffline tradeOffline = tradeOfflineMapper.queryShopWallData(Long.parseLong(shopId),payType);
        if(tradeOffline !=null){
            map.put("gmtCreate",DateUtil.fomatDate(tradeOffline.getGmtCreate(), DateUtil.sdfDay));
            map.put("realAmount",tradeOffline.getRealAmount());
        }

        return Response.getSuccess(map);
    }

    @Override
    public Response monthSettlementInfo(String shopId,String statisDate) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();

        Date date = DateUtil.fomatDate(statisDate);
        //判断时间是否为每月的第一天
        String str = statisDate.substring(8,10);
        if(str.equals("01")){
            Calendar c = Calendar.getInstance();
            c.setTime(date);
            c.add(Calendar.DAY_OF_MONTH, -1);// 今天-1天
            date = c.getTime();

        }
        //钱包的结算记录(钱包提现
        List<TradeOffline> tradeOfflineList = tradeOfflineMapper.queryShopWalletData(shopId,date);
        List<Map<String, Object>> shopTradeList = new ArrayList<Map<String, Object>>();
        for (TradeOffline tradeOffline : tradeOfflineList) {
            Map<String, Object> detail = new HashMap<String, Object>();
            detail.put("gmtCreate", tradeOffline.getGmtCreate());
            detail.put("realAmount", tradeOffline.getRealAmount());
            shopTradeList.add(detail);
        }
        if (shopTradeList.size() > 0) {
            map.put("shopTradeList", shopTradeList);
        }
        return Response.getSuccess(map);
    }


    @Override
    public Response daySettlementDetail(String shopId, String statisDate) throws ApplicationException {
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("shopId",Long.parseLong(shopId));
        param.put("statisDate",statisDate);

        //收款消费笔数 收款消费总金额
        map.put("statisDate",statisDate);
        ShopTradeStatisOutDTO shopTradeStatisOutDTO= tradeOfflineMapper.queryShopTradeData(param);

        if(shopTradeStatisOutDTO !=null){
            map.put("collectCount",shopTradeStatisOutDTO.getTotalNumber());
            map.put("collectAmount",shopTradeStatisOutDTO.getTotalRealAmount());
        }else{
            map.put("collectCount",0);
            map.put("collectAmount",0);
        }
        //券码核销笔数 券码核销金额
        OrderServiceGoodDetail orderServiceGoodDetail = orderServiceGoodDetailMapper.queryShopOrderData(param);
        if(orderServiceGoodDetail !=null){
            map.put("vitifyCount",orderServiceGoodDetail.getCount());
            map.put("vitifyAmount",orderServiceGoodDetail.getVerifyAmount());
        }else{
            map.put("vitifyCount",0);
            map.put("vitifyAmount",0);
        }

        //优惠券笔数 抵扣金额
        TradeOffline tradeOffline = tradeOfflineMapper.queryCouponData(param);
        if(tradeOffline !=null){
            map.put("couponCount",tradeOffline.getTotalCount());
            map.put("couponAmount",tradeOffline.getDiscountAmount());
        }else{
            map.put("couponCount",0);
            map.put("couponAmount",0);
        }


        return Response.getSuccess(map);
    }

    @Override
    public Response tradeList(String shopId, String statisDate, Integer transactionType, Integer payType,Integer type, Integer pageNo, Integer pageSize) throws ApplicationException {
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> param = new HashMap<String, Object>();
        List<Map<String, Object>> shopTradeList = new ArrayList<Map<String, Object>>();
        param.put("shopId",Long.parseLong(shopId));
        if(statisDate ==null){
            param.put("statisDate",new Date());
        }else{
            param.put("statisDate",statisDate);
        }

        if(type ==1){
            //收款消费笔数 收款消费总金额
            ShopTradeStatisOutDTO shopTradeStatisOutDTO= tradeOfflineMapper.queryShopTradeData(param);
            if(shopTradeStatisOutDTO !=null){

                map.put("count",shopTradeStatisOutDTO.getTotalNumber());
                map.put("amount",shopTradeStatisOutDTO.getTotalRealAmount());
            }

            if(transactionType !=null){
                param.put("transactionType",transactionType);
            }
            if(payType !=null){
                param.put("payType",payType);
            }

            int count = tradeOfflineMapper.queryTradeShopDataCount(param);
            if (count == 0) {
                map.put("shopTradeList", shopTradeList);
                return Response.getSuccess(map);
            }
            param.put("start", pageSize * (pageNo - 1));
            param.put("limit", pageSize);

            List<TradeOffline> tradeOfflineList = tradeOfflineMapper.queryTradeShopDataList(param);
            for(TradeOffline tradeOffline :tradeOfflineList){
                Map<String, Object> detail = new HashMap<String, Object>();
                detail.put("tradeDate", tradeOffline.getGmtCreate());
                detail.put("memberName", tradeOffline.getPayerName());
                detail.put("orderAmount", tradeOffline.getRealAmount());
                detail.put("payType", tradeOffline.getPayType());
                detail.put("transactionType", tradeOffline.getTransactionType());
                shopTradeList.add(detail);
            }
            if (shopTradeList.size() > 0) {
                map.put("shopTradeList", shopTradeList);
            }
        }else if(type ==2){//券码核销
            OrderServiceGoodDetail orderServiceGoodDetail = orderServiceGoodDetailMapper.queryShopOrderData(param);
            if(orderServiceGoodDetail !=null){
                map.put("count",orderServiceGoodDetail.getCount());
                map.put("amount",orderServiceGoodDetail.getVerifyAmount());
            }else{
                map.put("count",0);
                map.put("amount",0);
            }

            if(transactionType !=null){
                param.put("transactionType",transactionType);
            }
            if(payType !=null){
                param.put("payType",payType);
            }

            int count = orderServiceGoodDetailMapper.queryShopOrderDataCount(param);
            if (count == 0) {
                map.put("shopTradeList", shopTradeList);
                return Response.getSuccess(map);
            }
            param.put("start", pageSize * (pageNo - 1));
            param.put("limit", pageSize);

            List<ShopTradeStatisOutDTO> shopTradeStatisOutDTOList = orderServiceGoodDetailMapper.queryShopOrderDataList(param);
            for(ShopTradeStatisOutDTO shopTradeStatisOutDTO :shopTradeStatisOutDTOList){
                Map<String, Object> detail = new HashMap<String, Object>();
                detail.put("tradeDate", shopTradeStatisOutDTO.getGmtCreate());
                detail.put("memberName", shopTradeStatisOutDTO.getPayerName());
                detail.put("orderAmount", shopTradeStatisOutDTO.getRealAmount());
                detail.put("payType", shopTradeStatisOutDTO.getPayType());
                detail.put("transactionType", shopTradeStatisOutDTO.getTransactionType());
                shopTradeList.add(detail);
            }
            if (shopTradeList.size() > 0) {
                map.put("shopTradeList", shopTradeList);
            }


        }else if(type ==3){//商城商品

        }else{//优惠券
            TradeOffline tradeOffline = tradeOfflineMapper.queryCouponData(param);
            if(tradeOffline !=null){
                map.put("count",tradeOffline.getTotalCount());
                map.put("amount",tradeOffline.getDiscountAmount());
            }else{
                map.put("count",0);
                map.put("amount",0);
            }
            if(transactionType !=null){
                param.put("transactionType",transactionType);
            }
            if(payType !=null){
                param.put("payType",payType);
            }


            if (tradeOffline.getTotalCount() == 0) {
                map.put("shopTradeList", shopTradeList);
                return Response.getSuccess(map);
            }
            param.put("start", pageSize * (pageNo - 1));
            param.put("limit", pageSize);

            List<TradeOffline> tradeOfflineList = tradeOfflineMapper.queryCouponDataList(param);
            for(TradeOffline result :tradeOfflineList){
                Map<String, Object> detail = new HashMap<String, Object>();
                detail.put("tradeDate", result.getGmtCreate());
                detail.put("memberName", result.getPayerName());
                detail.put("orderAmount", result.getRealAmount());
                detail.put("payType", result.getPayType());
                detail.put("transactionType", result.getTransactionType());
                shopTradeList.add(detail);
            }
            if (shopTradeList.size() > 0) {
                map.put("shopTradeList", shopTradeList);
            }


        }

        return Response.getSuccess(map);
    }


    @Override
    public Response shopDrawBankInfo(String shopId) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        Shop shop = shopMapper.selectByPrimaryKey(Long.parseLong(shopId));
        if (shopId == null) {
            return Response.getError("商户信息不存在");
        }

        map.put("openBank", shop.getRecieveBank());
        map.put("accountName", shop.getRecieveName());
        map.put("bankNo", shop.getRecieveAccount());
        map.put("idNo", shop.getPersonId());
        map.put("openAdress", shop.getAccountArea());
        map.put("openNum", shop.getAccountBank());
        if (shop.getPrincipalName() != null) {
            map.put("financialName", shop.getPrincipalName());
        } else {
            map.put("financialName", null);
        }
        if (shop.getPrincipalMobile() != null) {
            map.put("financialPhone", shop.getPrincipalMobile());
        } else {
            map.put("financialPhone", null);
        }

        return Response.getSuccess(map);
    }

    @Override
    public Response drawList(String shopId, String groupId,Integer pageNo, Integer pageSize) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> param = new HashMap<String, Object>();
        List<Map<String, Object>> drawList = new ArrayList<Map<String, Object>>();

        param.put("shopId", Long.parseLong(shopId));


        TradeWithdraw result = tradeWithdrawMapper.queryDrawData(param);
        if(result != null){
            map.put("count", result.getNumber());
            map.put("totalAmount", result.getApplyAmount().toString());
        }

        Shop shop=shopMapper.selectShopInfo(Long.parseLong(shopId),Long.parseLong(groupId));
        //此处门店余额查询 暂时直连支付平台
        SimpleDateFormat   simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        Date date = new Date();
        String str = simpleDateFormat.format(date);
        String orgTranDateTime=str;
        Random random = new Random();
        int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数
        String orgOrderNum= str+rannum;//时间加随机数5位
        String SysTraceNum = StringUtil.getRandNumberStr(12);//交易流水号12位
        String UserId=shop.getShopGroupRelation().getPayMerchantCode()+"";

        String GroupId=shop.getGroup().getPayGroupCode();
        PayBalanceQuery payBalanceQuery=PayBalanceQuery.initialize(UserId,GroupId, SysTraceNum, orgTranDateTime, orgOrderNum);
        PayBalanceResult payResult=IPayAPI.accountBalanceQuery(payBalanceQuery,true);
        if (!PayBalanceResult.SUCCESS.equals(payResult.getRespCode())) {
            throw new ApplicationException(Rescode.FAIL,payResult.getMsgExt());
        }
        //此处余额需要查询支付平台
//        if(Tools.notEmpty(payResult.getCurBal())){
//            shopOutDTO.setBalance(Long.parseLong(payResult.getCurBal()));//余额
//        }
        if(Tools.notEmpty(payResult.getCurBalB())){
            map.put("lockAmount",payResult.getCurBalB());//锁定金额
        }else{
            map.put("lockAmount",0);//锁定金额
        }

        int count = tradeOfflineMapper.queryComsumeCount(param);
        if (count == 0) {
            map.put("drawList", drawList);
            return Response.getSuccess(map);
        }

        param.put("start", pageSize * (pageNo - 1));
        param.put("limit", pageSize);

        List<TradeWithdraw> tradeWithdrawList = tradeWithdrawMapper.tradeWithList(param);


        for (TradeWithdraw tradeWithdraw : tradeWithdrawList) {
            Map<String, Object> detail = new HashMap<String, Object>();
            detail.put("id", tradeWithdraw.getId());
            detail.put("statisDate", tradeWithdraw.getGmtCreate());
            detail.put("status", BizEnum.WithdrawStatus.fromType(tradeWithdraw.getStatus()).getName());
            detail.put("drawAmount", tradeWithdraw.getApplyAmount().toString());

            drawList.add(detail);
        }
        if (drawList.size() > 0) {
            map.put("drawList", drawList);
        }
        return Response.getSuccess(map);
    }

    @Override
    public Response detailDraw(String id) throws Exception {
        Map<String, Object> map = new HashMap<>();

        TradeDrawOutDTO tradeDrawOutDTO =tradeWithdrawMapper.queryTradeDrawDetail(Long.parseLong(id));

        if(tradeDrawOutDTO!=null){
            map.put("transType", BizEnum.TransactionType.fromType(tradeDrawOutDTO.getTransactionType()).getName());
            map.put("status", BizEnum.WithdrawStatus.fromType(tradeDrawOutDTO.getStatus()).getName());
            map.put("drawAmount", tradeDrawOutDTO.getApplyAmount().toString());
            if(tradeDrawOutDTO.getAfterApplyAmount() !=null){
                map.put("balanceAmount", tradeDrawOutDTO.getAfterApplyAmount().toString());
            }else{
                map.put("balanceAmount", "");
            }
            map.put("shopName", tradeDrawOutDTO.getShopName());
            map.put("gmtCreate", tradeDrawOutDTO.getGmtCreate());
            map.put("orderNo", tradeDrawOutDTO.getTraceNo());
            map.put("bankNo", StringReplaceUtil.bankCardReplaceWithStar(tradeDrawOutDTO.getCardNo()));
            map.put("bankName", tradeDrawOutDTO.getRecieveBank());
        }

        return Response.getSuccess(map);
    }

    @Override
    public Response updateWithdrawal(String shopId,Integer balance,Integer amount) throws Exception {
        Map<String, Object> map = new HashMap<>();

        Shop shopInfo = shopMapper.selectShopDataAndGroupId(Long.parseLong(shopId));

        Shop shop=shopMapper.selectShopInfo(Long.parseLong(shopId),shopInfo.getGroupId());
        if(shop==null){
            throw new ApplicationException("fail","门店不存在");
        }
        String groupId=shop.getGroup().getPayGroupCode();
        String merchantId=shop.getShopGroupRelation().getPayMerchantCode();
        String orgOrderNum =Const.PLATFORM_WITHDEAW+UtilFun.createOrderNum();
        
        PayTransferResult payResult=walletService.updateMerchantWithsDraw(merchantId, groupId, shop.getUserId(), amount, orgOrderNum);
        if(!PayResult.SUCCESS.equals(payResult.getRespCode())){
            throw new ApplicationException(payResult.getRespCode(),payResult.getMsgTxt());
        }
        
        //插入的数据修改填充
        TradeWithdraw tradeWithdraw = new TradeWithdraw();
        tradeWithdraw.setStatus(BizEnum.WithdrawStatus.WaitingForSettle.getType());
        if (payResult.getOrderId()!=null){
            tradeWithdraw.setWalletOrderId(payResult.getOrderId());
        }

        tradeWithdraw.setTraceNo(orgOrderNum);
        tradeWithdraw.setShopId(Long.parseLong(shopId));
        tradeWithdraw.setGroupId(shopInfo.getGroupId());
        tradeWithdraw.setFee(0);
        tradeWithdraw.setGmtCreate(new Date());
        tradeWithdraw.setGmtModified(new Date());
        tradeWithdraw.setSettleCode(merchantId);
        tradeWithdraw.setApplyAmount(amount);
        tradeWithdraw.setAfterApplyAmount(balance-amount);
        tradeWithdrawMapper.insertSelective(tradeWithdraw);
        TradeOffline tradeOffline=addTradeOffline(orgOrderNum, shopInfo.getGroupId(), amount, Long.parseLong(shopId), shop.getMerchantName(),1);
        tradeOfflineMapper.insertSelective(tradeOffline);

        return Response.getSuccess(map);
    }


    //shopOrAgent代理或门店标志：1表示门店，2表示代理
    public TradeOffline addTradeOffline(String orgOrderNum,Long groupId,Integer tranAmt,Long payerId,String payerName,int shopOrAgent){
        TradeOffline tradeOffline=new TradeOffline();
        Date date=new Date();
        tradeOffline.setGmtCreate(date);
        tradeOffline.setGmtModified(date);
        tradeOffline.setGroupId(groupId);
        tradeOffline.setOrderId(Const.PLATFORM_WITHDEAW+UtilFun.createOrderNum());
        tradeOffline.setPayerId(payerId);//付款者id号
        tradeOffline.setPayerName(payerName);//付款者姓名
        if(shopOrAgent==1) {
            tradeOffline.setPayerType((byte) CommonEnum.UserType.Store.getType());
        }else if(shopOrAgent==2){
            tradeOffline.setPayerType((byte) CommonEnum.UserType.Agents.getType());
        }
        tradeOffline.setPayType((byte) BizEnum.PaymentType.Wallet.getType());//支付方式 生成订单支付方式未知
        tradeOffline.setReceiverId(payerId+"");//接收者id        提现付款者接收者暂设置为同一
        tradeOffline.setReceiverName(payerName);//接收者 此处以核销录入数据
        if(shopOrAgent==1) {
            tradeOffline.setReceiverType((byte) CommonEnum.UserType.Store.getType());
        }else if(shopOrAgent==2){
            tradeOffline.setReceiverType((byte) CommonEnum.UserType.Agents.getType());
        }
        tradeOffline.setTransactionType((byte)BizEnum.TransactionType.Withdraw.getType());//交易类型
//		    tradeOffline.setSubType((byte)BizEnum.PaymentScene.Online.getType());//支付场景
        tradeOffline.setOrderAmount(tranAmt); //订单金额
        tradeOffline.setDiscountAmount(0);//折扣金额
        tradeOffline.setRealAmount(tranAmt);//实付金额
        tradeOffline.setTransactionStatus((byte)BizEnum.TransactionStatus.Proccessing.getType());//交易状态
        tradeOffline.setIsWallet(false);
        tradeOffline.setGoodType(null);//商品类型(线上用) ？
        tradeOffline.setMemo("平台申请提现");
        tradeOffline.setDetail("平台申请提现");
        tradeOffline.setMerchantNo(null);//商户号(对账用)
        tradeOffline.setTerminalNo(null);//商户终端号
        tradeOffline.setPayAccount(null);//支付卡号
        tradeOffline.setScanOrganization((byte)BizEnum.ScanInNetCompany.fuqianla.getType());//扫码付入网机构
        tradeOffline.setCrcodeStr(null);
        tradeOffline.setOldOrderId(null);
        tradeOffline.setDividableAmount(0);//可分润金额
        tradeOffline.setAttachStatus(BizEnum.ProfitCalculateStatus.NoDeal.getType());
        tradeOffline.setPayOrderid(orgOrderNum);//钱包充值
        tradeOffline.setPayBakOrderid(null);
        tradeOffline.setInNetCompany(null);//入网机构

        return tradeOffline;

    }

    @Override
    public Response shopBonusBalance(String shopId) throws ApplicationException {
        Map<String,Object> map = new HashMap<>();

        BonusVerifyShop bonusVerifyShop = bonusVerifyShopMapper.queryShopVeriftyStatus(Long.parseLong(shopId));
        if(bonusVerifyShop==null || bonusVerifyShop.getStatus()==2){
            map.put("status","不可核销");
            map.put("bonusNumber",bonusVerifyShop.getAmount());
        }else if(bonusVerifyShop.getStatus()==1){
            map.put("status","核销中");
            map.put("bonusNumber",bonusVerifyShop.getAmount());
        }

        //本月发放数额 和 总数
        Date date = new Date();
        BonusSendLog bonusSendLog = bonusSendLogMapper.queryMonthSendNumber(Long.parseLong(shopId),date);
        if(bonusSendLog!=null ){
            map.put("monthSendBonus",bonusSendLog.getAdjustAmount());
            map.put("totalSendBonus",bonusSendLog.getBonusAmount());
        }

        BonusVerifyLog bonusVerifyLog= bonusVerifyLogMapper.queryMonthVerifyNumber(Long.parseLong(shopId),date);
        if(bonusVerifyLog!=null ){
            map.put("monthVeriftyBonus",bonusVerifyLog.getAdjustAmount());
            map.put("totalVeriftyBonus",bonusVerifyLog.getBonusAmount());
        }

        return Response.getSuccess(map);
    }

    @Override
    public Response sendShopBonusList(String shopId, Integer pageNo, Integer pageSize) {
        Map<String,Object> map = new HashMap<>();
        Map<String, Object> param = new HashMap<String, Object>();
        List<Map<String, Object>> bonusList = new ArrayList<Map<String, Object>>();

        BonusSendLog result = bonusSendLogMapper.queryBounsSendShopTotal(Long.parseLong(shopId));
        if(result!=null ){
            map.put("startSendDate",result.getGmtCreate());
            map.put("shopSendTotalAmount",result.getAdjustAmount());
        }

        int count = bonusSendLogMapper.queryBonusSendShopMonth(Long.parseLong(shopId));
        if (count == 0) {
            map.put("bonusList", bonusList);
            return Response.getSuccess(map);
        }

        param.put("shopId",Long.parseLong(shopId));
        param.put("start", pageSize * (pageNo - 1));
        param.put("limit", pageSize);

        List<BonusSendLog> bonusSendLogList = bonusSendLogMapper.queryBonusSendShopMonthList(param);
        for(BonusSendLog bonusSendLog :bonusSendLogList){
            Map<String, Object> detail = new HashMap<String, Object>();
            detail.put("sendDate",bonusSendLog.getStringDate());
            detail.put("sendCount",bonusSendLog.getSendCount());
            detail.put("sendBonusAmount",bonusSendLog.getAdjustAmount());

            bonusList.add(detail);

        }
        if(bonusList.size()>0){
            map.put("bonusList", bonusList);
        }

        return Response.getSuccess(map);
    }


    @Override
    public Response shopMonthBonusVeriftyList(String shopId, Integer pageNo, Integer pageSize) throws ApplicationException {
        Map<String,Object> map = new HashMap<>();
        Map<String, Object> param = new HashMap<String, Object>();
        List<Map<String, Object>> bonusList = new ArrayList<Map<String, Object>>();

        BonusVerifyLog result = bonusVerifyLogMapper.queryBounsVerifyShopTotal(Long.parseLong(shopId));
        if(result!=null ){
            map.put("veriftyDate",DateUtil.fomatDate(result.getGmtCreate(), DateUtil.sdfDay));
            map.put("shopVeriftyTotalAmount",result.getAdjustAmount());
        }

        int count = bonusVerifyLogMapper.queryBonusVerifyShopMonth(Long.parseLong(shopId));
        if (count == 0) {
            map.put("bonusList", bonusList);
            return Response.getSuccess(map);
        }

        param.put("shopId",Long.parseLong(shopId));
        param.put("start", pageSize * (pageNo - 1));
        param.put("limit", pageSize);

        List<BonusVerifyLogOutDTO> bonusVerifyLogOutDTOList =bonusVerifyLogMapper.selectShopVerifyBonusMonthList(param);

        for(BonusVerifyLogOutDTO bonusVerifyLog :bonusVerifyLogOutDTOList){
//        for(BonusVerifyLog bonusVerifyLog :bonusVerifyLogList){
            Map<String, Object> detail = new HashMap<String, Object>();
            detail.put("statisDate",bonusVerifyLog.getStatisDate());
            detail.put("monthVeriftyCount",bonusVerifyLog.getMonthVeriftyCount());
            detail.put("monthVeriftyBonusAmount",bonusVerifyLog.getMonthVeriftyBonusAmount());

            TradeOffline tradeOffline = tradeOfflineMapper.queryBonusvalue(bonusVerifyLog.getStatisDate()+"-00",Long.parseLong(shopId));
            if(tradeOffline !=null){
                detail.put("monthDeductAmount",tradeOffline.getBonusValue());
            }
            bonusList.add(detail);

        }
        if(bonusList.size()>0){
            map.put("bonusList", bonusList);
        }

        return Response.getSuccess(map);
    }


    @Override
    public Response monthShopSendBonusDetail(String shopId, String stringDate, Integer pageNo, Integer pageSize) throws ApplicationException {
        Map<String,Object> map = new HashMap<>();
        Map<String, Object> param = new HashMap<String, Object>();
        List<Map<String, Object>> sendActivityList = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> bonusDaySendList = new ArrayList<Map<String, Object>>();

        param.put("shopId",Long.parseLong(shopId));
        param.put("stringDate",stringDate+"-00");

        BonusSendLog result = bonusSendLogMapper.queryMonthBonusSendData(param);

        map.put("sendDate",stringDate);
        if(result !=null){
            map.put("sendCount",result.getSendCount());
            map.put("sendBonusAmount",result.getAdjustAmount());
            map.put("sendMemberCount",result.getSendMemberCount());
        }

        List<BonusSendLog> bounSendLogList =bonusSendLogMapper.queryActivitySendBonusdata(param);
        for(BonusSendLog bonusSendLog : bounSendLogList){
            Map<String, Object> detail = new HashMap<String, Object>();
            detail.put("activityName",bonusSendLog.getActivityName());
            detail.put("number",bonusSendLog.getAdjustAmount());

            sendActivityList.add(detail);
        }
        if(sendActivityList.size()>0){
           map.put("sendActivityList",sendActivityList);
        }

        int count = bonusSendLogMapper.queryDaySendBonusCount(param);
        if(count ==0){
            map.put("bonusDaySendList", bonusDaySendList);
            return Response.getSuccess(map);
        }
        param.put("start", pageSize * (pageNo - 1));
        param.put("limit", pageSize);

        List<BonusSendLog> bounSendLogList2 =bonusSendLogMapper.queryDaySendBonusdata(param);
        for(BonusSendLog bonusSendLog : bounSendLogList2){
            Map<String, Object> dayDetail = new HashMap<String, Object>();
            dayDetail.put("gmtCreate",bonusSendLog.getGmtCreate());
            dayDetail.put("daySendCount",bonusSendLog.getSendCount());
            dayDetail.put("daySendTotalCount",bonusSendLog.getAdjustAmount());

            bonusDaySendList.add(dayDetail);
        }
        if(bonusDaySendList.size()>0){
           map.put("bonusDaySendList",bonusDaySendList);
        }

        return Response.getSuccess(map);
    }



    @Override
    public Response monthVerifyDetail(String shopId, String stringDate, Integer pageNo, Integer pageSize) throws ApplicationException {

        Map<String,Object> map = new HashMap<>();
        Map<String, Object> param = new HashMap<String, Object>();
        List<Map<String, Object>> bonusDayVerifyList = new ArrayList<Map<String, Object>>();

        param.put("shopId",Long.parseLong(shopId));
        param.put("stringDate",stringDate+"-00");

        BonusVerifyLog result = bonusVerifyLogMapper.queryMonthBonusVerifyData(param);

        map.put("verifyDate",stringDate);
        if(result !=null){
            map.put("verifyCount",result.getVerifyCount());
            map.put("verifyToatlNumber",result.getAdjustAmount());
            map.put("verifyDeductAmount",result.getBonusAmount());
        }


        int count = bonusVerifyLogMapper.queryDayVerifyBonusCount(param);
        if(count ==0){
            map.put("bonusDayVerifyList", bonusDayVerifyList);
            return Response.getSuccess(map);
        }
        param.put("start", pageSize * (pageNo - 1));
        param.put("limit", pageSize);

//        List<BonusVerifyLog> bonusVerifyLogList =bonusVerifyLogMapper.queryDayVerifyBonusdata(param);
        List<BonusVerifyLogOutDTO> bonusVerifyLogOutDTOList =bonusVerifyLogMapper.queryDayVerifyBonusdata(param);
        for(BonusVerifyLogOutDTO bonusVerifyLog : bonusVerifyLogOutDTOList){
            Map<String, Object> dayDetail = new HashMap<String, Object>();
            dayDetail.put("gmtCreate",DateUtil.fomatDate(bonusVerifyLog.getGmtCreate(), DateUtil.sdfDay));
            dayDetail.put("dayVerifyCount",bonusVerifyLog.getVerifyCount());
            dayDetail.put("dayVerifyAmount",bonusVerifyLog.getAdjustAmount());
            TradeOffline tradeOffline = tradeOfflineMapper.queryDayBonusvalue(DateUtil.fomatDate(bonusVerifyLog.getGmtCreate(), DateUtil.sdfDay),Long.parseLong(shopId));
            if(tradeOffline !=null){
                dayDetail.put("dayDeductAmount",tradeOffline.getBonusValue());
            }
            bonusDayVerifyList.add(dayDetail);
        }
        if(bonusDayVerifyList.size()>0){
            map.put("bonusDayVerifyList",bonusDayVerifyList);
        }

        return Response.getSuccess(map);
    }


    @Override
    public Response daySendBonusDetail(String shopId, String statisDate, Integer pageNo, Integer pageSize) throws ApplicationException {
        Map<String,Object> map = new HashMap<>();
        Map<String, Object> param = new HashMap<String, Object>();
        List<Map<String, Object>> sendMemberDetailList = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> sendActivityList = new ArrayList<Map<String, Object>>();

        param.put("shopId",Long.parseLong(shopId));
        param.put("statisDate",statisDate);
        BonusSendLog result = bonusSendLogMapper.queryDayBonusSendData(param);

        map.put("dateTime",statisDate);
        if(result !=null){
            map.put("sendCount",result.getSendCount());
            map.put("sendBonusNumber",result.getAdjustAmount());
            map.put("sendMemberCount",result.getSendMemberCount());
        }


        List<BonusSendLog> bounSendLogList =bonusSendLogMapper.queryActivityDaySendBonusdata(param);
        for(BonusSendLog bonusSendLog : bounSendLogList){
            Map<String, Object> detail = new HashMap<String, Object>();
            detail.put("activityName",bonusSendLog.getActivityName());
            detail.put("number",bonusSendLog.getAdjustAmount());

            sendActivityList.add(detail);
        }
        if(sendActivityList.size()>0){
            map.put("sendActivityList",sendActivityList);
        }

        int count = bonusSendLogMapper.queryDaySendBonusCountDetail(param);
        if(count ==0){
            map.put("sendMemberDetailList", sendMemberDetailList);
            return Response.getSuccess(map);
        }
        param.put("start", pageSize * (pageNo - 1));
        param.put("limit", pageSize);

        List<BonusSendLog> bounSendLogList2 =bonusSendLogMapper.queryDaySendBonusDetailList(param);
        for(BonusSendLog bonusSendLog : bounSendLogList2){
            Map<String, Object> dayDetail = new HashMap<String, Object>();
            dayDetail.put("tradeId",bonusSendLog.getOrderId());
            dayDetail.put("stringDate",bonusSendLog.getGmtCreate());
            dayDetail.put("memberName",bonusSendLog.getActivityName());
            dayDetail.put("daySendBonusAmount",bonusSendLog.getAdjustAmount());
            dayDetail.put("orderAmount",bonusSendLog.getBonusAmount());

            sendMemberDetailList.add(dayDetail);
        }
        if(sendMemberDetailList.size()>0){
            map.put("sendMemberDetailList",sendMemberDetailList);
        }

        return Response.getSuccess(map);


    }


    @Override
    public Response dayVerifyDetail(String shopId, String statisDate, Integer pageNo, Integer pageSize) throws ApplicationException {
        Map<String,Object> map = new HashMap<>();
        Map<String, Object> param = new HashMap<String, Object>();
        List<Map<String, Object>> dayVerifyDetailList = new ArrayList<Map<String, Object>>();

        param.put("shopId",Long.parseLong(shopId));
        param.put("statisDate",statisDate);
        BonusVerifyLog result = bonusVerifyLogMapper.queryDayBonusVerifyData(param);

        map.put("dateTime",statisDate);
        if(result !=null){
            map.put("verifyCount",result.getVerifyCount());
            map.put("verifyBonusNumber",result.getAdjustAmount());
            map.put("amount",result.getBonusAmount());
            map.put("verifyMemberCount",result.getMemberCount());
        }

        int count = bonusVerifyLogMapper.queryDayVerifyBonusCountDetail(param);
        if(count ==0){
            map.put("dayVerifyDetailList", dayVerifyDetailList);
            return Response.getSuccess(map);
        }
        param.put("start", pageSize * (pageNo - 1));
        param.put("limit", pageSize);

        List<BonusVerifyLogOutDTO> bonusVerifyLogList =bonusVerifyLogMapper.queryDayVerifyBonusDetailList(param);
//        List<BonusVerifyLog> bonusVerifyLogList =bonusVerifyLogMapper.queryDayVerifyBonusDetailList(param);
        for(BonusVerifyLogOutDTO bonusVerifyLog : bonusVerifyLogList){
            Map<String, Object> dayDetail = new HashMap<String, Object>();
            dayDetail.put("tradeId",bonusVerifyLog.getOrderId());
            dayDetail.put("memberId",bonusVerifyLog.getMemberId());
            dayDetail.put("stringDate",bonusVerifyLog.getGmtCreate());
            if(bonusVerifyLog.getMemberName()!=null){
                dayDetail.put("memberName",bonusVerifyLog.getMemberName());
            }else{
                dayDetail.put("memberName","");
            }
            dayDetail.put("bonusVerifyNumber",bonusVerifyLog.getAdjustAmount());
            dayDetail.put("bonusAmount",bonusVerifyLog.getBonusAmount());

            dayVerifyDetailList.add(dayDetail);
        }
        if(dayVerifyDetailList.size()>0){
            map.put("dayVerifyDetailList",dayVerifyDetailList);
        }

        return Response.getSuccess(map);
    }

    @Override
    public Response bonusChange(String shopId) throws ApplicationException {
        Map<String,Object> map = new HashMap<>();

        List<Map<String, Object>> bonusVerifyList = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> bonusList2 = new ArrayList<Map<String, Object>>();
        //核销 会员核销积分 //暂未查余额要修改
        List<BonusVerifyLog> bonusVerifyLogList = bonusVerifyLogMapper.queryMemberVerifyBonus(Long.parseLong(shopId));
        for(BonusVerifyLog bonusVerifyLog :bonusVerifyLogList){
            Map<String,Object> detail = new HashMap<>();
            detail.put("id",bonusVerifyLog.getId());
            detail.put("userType",bonusVerifyLog.getUserType());
            detail.put("memberName",bonusVerifyLog.getMemberName());
            detail.put("gmtCreate",bonusVerifyLog.getGmtCreate());
            detail.put("adjustAmount","+"+bonusVerifyLog.getAdjustAmount().toString());
            //核销的余额待修改
            detail.put("balanceAmount",bonusVerifyLog.getBonusAmount());
            detail.put("type",1);

            bonusVerifyList.add(detail);
        }

        List<BonusShopSettleLog> bonusShopSettleLogList = bonusShopSettleLogMapper.bonusShopSettleLogList(Long.parseLong(shopId));
        for(BonusShopSettleLog bonusShopSettleLog :bonusShopSettleLogList){
            Map<String,Object> detail2 = new HashMap<>();
            detail2.put("id",bonusShopSettleLog.getId());
            detail2.put("userType",bonusShopSettleLog.getUserbase().getUserType());
            detail2.put("memberName",bonusShopSettleLog.getUserbase().getUsername());
            detail2.put("gmtCreate",bonusShopSettleLog.getGmtCreate());
            detail2.put("adjustAmount","-"+bonusShopSettleLog.getSettleAmount().toString());
            detail2.put("balanceAmount",bonusShopSettleLog.getSettleBalance());//余额
            detail2.put("type",2);
            bonusList2.add(detail2);
        }
        bonusVerifyList.addAll(bonusList2);
        if(bonusVerifyList.size()>0){
          map.put("bonusVerifyList",bonusVerifyList);
        }



        return Response.getSuccess(map);
    }

    @Override
    public Response adjustBonusDetail(String id, Integer type) throws ApplicationException {
        Map<String,Object> map = new HashMap<>();
        if(type ==1){
            BonusVerifyLog bonusVerifyLog = bonusVerifyLogMapper.queryBonusVerifyChangeDetail(Long.parseLong(id));

            if(bonusVerifyLog !=null){
                map.put("type",bonusVerifyLog.getUserType());
                map.put("operatorName",bonusVerifyLog.getMemberName());
                map.put("gmtCreate",bonusVerifyLog.getGmtCreate());
                map.put("adjustAmount","+"+bonusVerifyLog.getAdjustAmount().toString());
                map.put("startBonusBalance",null);
                map.put("endBonusBalance",null);
                map.put("memo",bonusVerifyLog.getMemo());
            }
        }else{
            BonusShopSettleLog bonusShopSettleLog = bonusShopSettleLogMapper.queryBonusInfoById(Long.parseLong(id));
            if(bonusShopSettleLog !=null){
                map.put("type",bonusShopSettleLog.getUserbase().getUserType());
                map.put("operatorName",bonusShopSettleLog.getUserbase().getUsername());
                map.put("gmtCreate",bonusShopSettleLog.getGmtCreate());
                map.put("adjustAmount","-"+bonusShopSettleLog.getSettleAmount().toString());
                map.put("startBonusBalance",bonusShopSettleLog.getSettleAmount()+bonusShopSettleLog.getSettleBalance());
                map.put("endBonusBalance",bonusShopSettleLog.getSettleBalance());
                map.put("memo",bonusShopSettleLog.getMemo());
            }
        }

        return Response.getSuccess(map);
    }



    @Override
    public Response shopDetail(String shopId) throws ApplicationException {
        Map<String,Object> map = new HashMap<>();

        //取得门店信息
        Shop shop = shopMapper.queryshopDetail(Long.parseLong(shopId));
        if(shop ==null){
            return Response.getError("门店信息不存在");
        }
		map.put("icon",shop.getIcon());
        map.put("shopName",shop.getMerchantName());
        if(shop.getShopScore() !=null){
            BigDecimal b = new   BigDecimal(shop.getShopScore());
            float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
            map.put("shopScore",f1);
        }else{
            map.put("shopScore",5);
        }
        map.put("industryName",shop.getIndustryName());
        if(shop.getShopTotalAmount()==0){
            map.put("avgAmount",0);
        }else{
            map.put("avgAmount",shop.getShopTotalAmount()/shop.getShopTotalCount());
        }
        map.put("wordTime",shop.getWorkTime());
        map.put("shopPhone",shop.getPhone());
        map.put("address",shop.getAddressProvince()+shop.getAddressCity()+shop.getAddressDistrict()+shop.getAddress());
        map.put("memo",shop.getMemo());



        //取得门店评价  显示2条必须是显示的
        Map<String,Object> param=new HashMap<String,Object>();
        param.clear();
        param.put("shopId", Long.parseLong(shopId));
        param.put("commentType",BizEnum.CommentType.Shop.getType());
        param.put("auditStatus",1);
        param.put("goodId", null);
        param.put("start", 0);
        param.put("limit", 2);//取2行
        List<MallGoodComment> mallGoodComments = mallGoodCommentMapper.selectCarShopOrGoodComment(param);
        List<Map<String,Object>> commentList = new ArrayList<Map<String, Object>>();
        for(MallGoodComment mallGoodComment:mallGoodComments){
            Map<String, Object> goodCommentMap = new HashMap<String, Object>();
            if(mallGoodComment.getAuditStatus()==1){
                goodCommentMap.put("comment_id",mallGoodComment.getId());
                if(mallGoodComment.getIsCryptonym()){
                    goodCommentMap.put("member_icon","");
                    goodCommentMap.put("member_name","匿名用户");
                }
                else{
                    goodCommentMap.put("member_icon",mallGoodComment.getMemberIcon());
                    goodCommentMap.put("member_name",mallGoodComment.getMemberName());
                }
                if(mallGoodComment.getCommentLevel()!=null){
                    goodCommentMap.put("score",mallGoodComment.getCommentLevel());
                }else{
                    goodCommentMap.put("score",5);
                }
                goodCommentMap.put("comment_date",DateUtil.fomatDate(mallGoodComment.getGmtCreate(),DateUtil.sdfDayC));
                goodCommentMap.put("comment_content",mallGoodComment.getContent());
//			String[] pics = new String[5];
                if(mallGoodComment.getPicUrls()!=null){

                    String[] pics = mallGoodComment.getPicUrls().split(",");
                    for (int i=0;i<pics.length;i++){
                        String keyStr = "comment_imagepath"+i;
                        goodCommentMap.put(keyStr,pics[i]);
                    }
                }
                commentList.add(goodCommentMap);
            }

        }

        if(commentList.size()>0) {
            map.put("comment_list", commentList);
        }

        return Response.getSuccess(map);
    }

    @Override
    public Response activityList(String shopId, Integer type, Integer pageNo, Integer pageSize) {
        Map<String,Object> map = new HashMap<>();
        Map<String, Object> param = new HashMap<String, Object>();
        List<Map<String, Object>> activityList = new ArrayList<Map<String, Object>>();

        param.put("shopId",Long.parseLong(shopId));
        if(type==1){//进行中
            param.put("activityStatus", ActivityEnum.ActivityStatus.Proccessing.getType());
        }else if(type==2){//待开始
            param.put("activityStatus", ActivityEnum.ActivityStatus.Waiting.getType());
        }else{//已结束
            param.put("activityStatus", ActivityEnum.ActivityStatus.Over.getType());
        }

        int count = activityUnroutineMapper.queryShopActivityCount(param);
        if(count ==0){
            map.put("activityList", activityList);
            return Response.getSuccess(map);
        }
        param.put("start", pageSize * (pageNo - 1));
        param.put("limit", pageSize);

        List<ActivityUnroutine> activityUnroutineList= activityUnroutineMapper.queryShopActivityList(param);
        for(ActivityUnroutine activityUnroutine:activityUnroutineList){
            Map<String,Object> detail = new HashMap<>();
            detail.put("activityId",activityUnroutine.getActivityId());
            detail.put("activityName",activityUnroutine.getActivityName());
            detail.put("startTime",activityUnroutine.getStartTime());
            detail.put("endTime",activityUnroutine.getEndTime());
            detail.put("sendType",activityUnroutine.getSendType());

            activityList.add(detail);
        }
        if(activityList.size()>0){
            map.put("activityList",activityList);
        }


        return Response.getSuccess(map);
    }

    @Override
    public Response activityDetail(String activityId) throws ApplicationException {
        Map<String,Object> map = new HashMap<>();
        ActivityUnroutine activityUnroutine = activityUnroutineMapper.queryActivityDetail(Long.parseLong(activityId));
        if(activityUnroutine ==null){
            return Response.getError("活动信息不存在");

        }
        map.put("activityIcon", activityUnroutine.getIconUrl());
        map.put("activityName", activityUnroutine.getActivityName());
        map.put("activityStatus", activityUnroutine.getStatus());
        map.put("startTime", activityUnroutine.getStartTime());
        map.put("endTime", activityUnroutine.getEndTime());
        map.put("operator", activityUnroutine.getUsername());
        map.put("activityType", activityUnroutine.getActivityType());
        map.put("sendType", activityUnroutine.getSendType());
        map.put("activityLocal", activityUnroutine.getActivityPlatformType());
        map.put("activityPriority", activityUnroutine.getPriority());
        if(activityUnroutine.getMaxAmount()==null){
            map.put("maxAmount", -1);//表示无上限
            map.put("remainAmount", -1);
        }else{
            map.put("maxAmount", activityUnroutine.getMaxAmount());
            map.put("remainAmount", activityUnroutine.getMaxAmount()-activityUnroutine.getUsedAmount());
        }
        map.put("usedAmount",activityUnroutine.getUsedAmount());
        map.put("memberRiented",activityUnroutine.getMemberRiented());
        map.put("userGradeList",activityUnroutine.getUserGradeList());
        map.put("shopCount",activityUnroutine.getShopCount());

        return Response.getSuccess(map);
    }

    @Override
    public Response activityContent(String shopId,String activityId,Integer sendType) throws ApplicationException {
        Map<String,Object> map = new HashMap<>();
        List<Map<String, Object>> activityRuleList1 = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> activityRuleList2 = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> activityRuleList3 = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> activityRuleList4 = new ArrayList<Map<String, Object>>();

        ActivityUnroutine activityUnroutine = activityUnroutineMapper.queryActivityDetail(Long.parseLong(activityId));
        if(activityUnroutine ==null){
            return Response.getError("活动信息不存在");

        }

        ActivityUnroutineShopPlus activityUnroutineShopPlus =activityUnroutineShopPlusMapper.selectByActivityIdAndShopId(Long.parseLong(shopId),Long.parseLong(activityId));

        int amount =0;
        if(activityUnroutineShopPlus!=null){
            amount =activityUnroutineShopPlus.getAdditionalFaceValue();
        }

        map.put("activityIcon", activityUnroutine.getIconUrl());
        map.put("activityName", activityUnroutine.getActivityName());
        map.put("activityStatus", activityUnroutine.getStatus());
        map.put("startTime", activityUnroutine.getStartTime());
        map.put("endTime", activityUnroutine.getEndTime());
        map.put("operator", activityUnroutine.getUsername());
        map.put("sendType", sendType);

        List<ActivityUnroutineRule> activityUnroutineRuleList = activityUnroutineRuleMapper.queryActivityUnroutineRule(Long.parseLong(activityId),sendType);
        for(ActivityUnroutineRule activityUnroutineRule:activityUnroutineRuleList){
            Map<String,Object> detail = new HashMap<>();

            if(activityUnroutineRule.getSendType()==1){//返现
                detail.put("minAmount",activityUnroutineRule.getMiniAmount());
                if(activityUnroutineRule.getBackMoneyMode()==1){//现金 2:百分比
                    detail.put("activitySend",activityUnroutineRule.getFaceValue().floatValue()/100);
                    detail.put("shopSend",(activityUnroutineRule.getFaceValue()+amount)/100);
                }else{
                    detail.put("activitySend",activityUnroutineRule.getFaceValue().floatValue()/100+"%");
                    detail.put("shopSend",(activityUnroutineRule.getFaceValue()+amount)/100+"%");
                }
            }

            activityRuleList1.add(detail);
        }
        map.put("activityRuleList1",activityRuleList1);

        
        for(ActivityUnroutineRule activityUnroutineRule:activityUnroutineRuleList){
            Map<String,Object> detail = new HashMap<>();
            if(activityUnroutineRule.getSendType()==2){//红包
                detail.put("minAmount",activityUnroutineRule.getMiniAmount());
                String redpackageName="";
                String[] redpackageIds = activityUnroutineRule.getRedpackageId().toString().split(",");
                for(int i = 0; i < redpackageIds.length; i++){
                    Redpackage redpackage = redpackageMapper.selectByPrimaryKey(Long.parseLong(redpackageIds[i]));
                    redpackageName = redpackage.getName()+',';
                }
                redpackageName.substring(0,redpackageName.length()-1);
                detail.put("redpackageName",redpackageName);
            }
            activityRuleList2.add(detail);

        }

        map.put("activityRuleList2",activityRuleList2);

        for(ActivityUnroutineRule activityUnroutineRule:activityUnroutineRuleList){
            Map<String,Object> detail = new HashMap<>();

            if(activityUnroutineRule.getSendType()==3){//优惠券
                detail.put("minAmount",activityUnroutineRule.getMiniAmount());
                String couponName="";
                String[] couponIds = activityUnroutineRule.getCouponId().toString().split(",");
                for(int i = 0; i < couponIds.length; i++){
                    Coupon coupon = couponMapper.selectByPrimaryKey(Long.parseLong(couponIds[i]));
                    couponName = coupon.getName()+',';
                }
                couponName.substring(0,couponName.length()-1);
                detail.put("couponName",couponName);
            }
            activityRuleList3.add(detail);

        }
        map.put("activityRuleList3",activityRuleList3);



        for(ActivityUnroutineRule activityUnroutineRule:activityUnroutineRuleList){
            Map<String,Object> detail = new HashMap<>();

            if(activityUnroutineRule.getSendType()==4){//积分
                detail.put("minAmount",activityUnroutineRule.getMiniAmount());
                if(activityUnroutineRule.getBackMoneyMode()==1){//现金 2:百分比
                    detail.put("activitySend",activityUnroutineRule.getFaceValue().floatValue()/100);
                    detail.put("shopSend",(activityUnroutineRule.getFaceValue()+amount)/100);
                }else{
                    detail.put("activitySend",activityUnroutineRule.getFaceValue().floatValue()/100+"%");
                    detail.put("shopSend",(activityUnroutineRule.getFaceValue()+amount)/100+"%");
                }
            }
            activityRuleList4.add(detail);
        }
        map.put("activityRuleList4",activityRuleList4);


        return Response.getSuccess(map);
    }

    @Override
    public Response activityMemo(String activityId) throws ApplicationException {
        Map<String,Object> map = new HashMap<>();

        ActivityUnroutine activityUnroutine = activityUnroutineMapper.queryActivityDetail(Long.parseLong(activityId));
        if(activityUnroutine ==null){
            return Response.getError("活动信息不存在");
        }

        map.put("activityIcon", activityUnroutine.getIconUrl());
        map.put("activityName", activityUnroutine.getActivityName());
        map.put("activityStatus", activityUnroutine.getStatus());
        map.put("startTime", activityUnroutine.getStartTime());
        map.put("endTime", activityUnroutine.getEndTime());
        map.put("operator", activityUnroutine.getUsername());
        map.put("content", activityUnroutine.getContent());
        map.put("mainPageUrl", activityUnroutine.getMainPageUrl());


        return Response.getSuccess(map);
    }


    @Override
    public Response couponList(String shopId, Integer type, Integer pageNo, Integer pageSize) throws ApplicationException {
        Map<String ,Object> map = new HashMap<>();
        Map<String, Object> param = new HashMap<String, Object>();
        List<Map<String, Object>> couponList = new ArrayList<Map<String, Object>>();

        param.put("shopId",Long.parseLong(shopId));
        param.put("type",type);//优惠券类型 type 1:活动中的 2:已结束的 3:优惠券审核记录

        int count =  couponMapper.queryShopJoinCouponCount(param);
        if(count ==0){
            map.put("couponList", couponList);
            return Response.getSuccess(map);
        }
        param.put("start", pageSize * (pageNo - 1));
        param.put("limit", pageSize);

        List<Coupon> coupons= couponMapper.queryShopJoinCouponList(param);
        for(Coupon coupon:coupons){
            Map<String,Object> detail = new HashMap<>();
            detail.put("couponId",coupon.getId());
            detail.put("couponName",coupon.getName());
            detail.put("couponType",coupon.getCouponType());
            detail.put("couponStatus",coupon.getStatus());
            if(coupon.getValidTimeType()==1){
                detail.put("stringday",DateUtil.fomatDate(coupon.getValidStartTime(), DateUtil.sdfDay)+"至"+
                        DateUtil.fomatDate(coupon.getValidEndTime(), DateUtil.sdfDay));
            }else{
                detail.put("stringday","领取后"+coupon.getDays()+"后有效");
            }

            couponList.add(detail);

        }
        if(couponList.size()>0){
            map.put("couponList",couponList);
        }
        return Response.getSuccess(map);
    }

    @Override
    public Response shopEffect(String activityId, String shopId, Integer sendType, Integer pageNo, Integer pageSize) {
        Map<String,Object> map = new HashMap<>();
        List<Map<String, Object>> sendList = new ArrayList<Map<String, Object>>();

        ActivityUnroutine activityUnroutine = activityUnroutineMapper.queryActivityDetail(Long.parseLong(activityId));
        if(activityUnroutine ==null){
            return Response.getError("活动信息不存在");

        }

        map.put("activityIcon", activityUnroutine.getIconUrl());
        map.put("activityName", activityUnroutine.getActivityName());
        map.put("activityStatus", activityUnroutine.getStatus());
        map.put("startTime", activityUnroutine.getStartTime());
        map.put("endTime", activityUnroutine.getEndTime());
        map.put("operator", activityUnroutine.getUsername());
        map.put("sendType", sendType);


        Map<String, Object> param = new HashMap<String, Object>();
        param.put("shopId",shopId);
        param.put("activityId",activityId);

        switch (sendType)
        {
            case 1://返现




                break;
            case 2://红包
                RedpackageUser redpackageUser =redpackageUserMapper.queryShopSendRedpackData(Long.parseLong(shopId),Long.parseLong(activityId));
                if(redpackageUser !=null){
                    map.put("shopStartTime", redpackageUser.getGmtCreate());
                    map.put("shopSendTotalNumber", redpackageUser.getRealAmount());
                    map.put("shopSendTotalCount", redpackageUser.getSendCount());
                    map.put("shopSendMemberTotalCount", redpackageUser.getSendMemberCount());
                }
                param.put("start", pageSize * (pageNo - 1));
                param.put("limit", pageSize);

                List<RedpackageUser> redpackageUserList=redpackageUserMapper.queryShopActivitySendRedpackList(param);
                for (RedpackageUser result :redpackageUserList){
                    Map<String,Object> detail = new HashMap<>();
                    detail.put("gmtCreate",result.getGmtCreate());
                    detail.put("daySendCount",result.getSendCount());
                    detail.put("daySendNumber",result.getRealAmount());
                    sendList.add(detail);
                }

                map.put("sendList",sendList);

                break;
            case 3://优惠券
                CouponUser conpouUser =couponUserMapper.queryShopSendCouponData(Long.parseLong(shopId),Long.parseLong(activityId));
                if(conpouUser !=null){
                    map.put("shopStartTime", conpouUser.getGmtCreate());
                    map.put("shopSendTotalNumber", conpouUser.getFaceValue());
                    map.put("shopSendTotalCount", conpouUser.getCount());
                    map.put("shopSendMemberTotalCount", conpouUser.getSendMemberCount());
                }
                param.put("start", pageSize * (pageNo - 1));
                param.put("limit", pageSize);

                List<CouponUser> couponUserList=couponUserMapper.queryShopActivitySendCouponList(param);
                for (CouponUser result :couponUserList){
                    Map<String,Object> detail = new HashMap<>();
                    detail.put("gmtCreate",result.getGmtCreate());
                    detail.put("daySendCount",result.getCount());
                    detail.put("daySendNumber",result.getFaceValue());
                    sendList.add(detail);
                }

                map.put("sendList",sendList);
                break;
            case 4://积分

                BonusSendLog bonusSendLog = bonusSendLogMapper.queryShopSendBonusData(Long.parseLong(shopId),Long.parseLong(activityId));
                if(bonusSendLog !=null){
                    map.put("shopStartTime", bonusSendLog.getGmtCreate());
                    map.put("shopSendTotalNumber", bonusSendLog.getAdjustAmount());
                    map.put("shopSendTotalCount", bonusSendLog.getSendCount());
                    map.put("shopSendMemberTotalCount", bonusSendLog.getSendMemberCount());
                }

                param.put("start", pageSize * (pageNo - 1));
                param.put("limit", pageSize);
                List<BonusSendLog> bonusSendLogList=bonusSendLogMapper.queryShopActivitySendBonusList(param);
                for (BonusSendLog result :bonusSendLogList){
                    Map<String,Object> detail = new HashMap<>();
                    detail.put("gmtCreate",result.getGmtCreate());
                    detail.put("daySendCount",result.getSendCount());
                    detail.put("daySendNumber",result.getAdjustAmount());
                    sendList.add(detail);
                }

                map.put("sendList",sendList);


                break;
        }

        return Response.getSuccess(map);
    }

    @Override
    public Response dayActivityDetail(String activityId, String shopId, Integer sendType,String statisDate, Integer pageNo, Integer pageSize) throws ApplicationException {

        Map<String,Object> map = new HashMap<>();
        List<Map<String, Object>> sendDayDetailList = new ArrayList<Map<String, Object>>();


        Map<String, Object> param = new HashMap<String, Object>();
        param.put("shopId",shopId);
        param.put("activityId",activityId);
        param.put("statisDate",statisDate);
        switch (sendType)
        {
            case 1://返现




                break;
            case 2://红包
                 RedpackageUser redpackageUser =redpackageUserMapper.queryShopDaySendRedpackData(param);
                if(redpackageUser !=null){
                    map.put("statisDate", redpackageUser.getGmtCreate());
                    map.put("sendNumber", redpackageUser.getRealAmount());
                    map.put("sendCount", redpackageUser.getSendCount());
                    map.put("sendMemberCount", redpackageUser.getSendMemberCount());
                }
                param.put("start", pageSize * (pageNo - 1));
                param.put("limit", pageSize);

                List<RedpackageUser> redpackageUserList=redpackageUserMapper.queryShopActivityDaySendRedpackList(param);
                for (RedpackageUser result :redpackageUserList){
                    Map<String,Object> detail = new HashMap<>();
                    detail.put("gmtCreate",result.getGmtCreate());
                    detail.put("memberName",result.getMemberName());
                    detail.put("customerAmount",result.getOrderAmount());
                    detail.put("tradeId",result.getId());
                    detail.put("daySendNumber",result.getRealAmount());
                    sendDayDetailList.add(detail);
                }

                map.put("sendDayDetailList",sendDayDetailList);

                break;
            case 3://优惠券
                CouponUser conpouUser =couponUserMapper.queryShopSendDayCouponData(param);
                if(conpouUser !=null){
                    map.put("statisDate", conpouUser.getGmtCreate());
                    map.put("sendNumber", conpouUser.getFaceValue());
                    map.put("sendCount", conpouUser.getCount());
                    map.put("sendMemberCount", conpouUser.getSendMemberCount());
                }
                param.put("start", pageSize * (pageNo - 1));
                param.put("limit", pageSize);

                List<CouponUser> couponUserList=couponUserMapper.queryShopActivitySendDayCouponList(param);
                for (CouponUser result :couponUserList){
                    Map<String,Object> detail = new HashMap<>();
                    detail.put("gmtCreate",result.getGmtCreate());
                    detail.put("memberName",result.getMemberName());
                    detail.put("customerAmount",result.getRealAmount());
                    detail.put("daySendNumber",result.getFaceValue());
                    detail.put("tradeId",result.getId());
                    sendDayDetailList.add(detail);
                }

                map.put("sendDayDetailList",sendDayDetailList);
                break;
            case 4://积分

                BonusSendLog bonusSendLog = bonusSendLogMapper.queryShopSendDayBonusDetail(param);
                if(bonusSendLog !=null){
                    map.put("statisDate", bonusSendLog.getGmtCreate());
                    map.put("sendNumber", bonusSendLog.getAdjustAmount());
                    map.put("sendCount", bonusSendLog.getSendCount());
                    map.put("sendMemberCount", bonusSendLog.getSendMemberCount());
                }

                param.put("start", pageSize * (pageNo - 1));
                param.put("limit", pageSize);
                List<BonusSendLog> bonusSendLogList=bonusSendLogMapper.queryShopActivitySendDayBonusList(param);
                for (BonusSendLog result :bonusSendLogList){
                    Map<String,Object> detail = new HashMap<>();
                    detail.put("gmtCreate",result.getGmtCreate());
                    detail.put("memberName",result.getMemberName());
                    detail.put("customerAmount",result.getRealAmount());
                    detail.put("daySendNumber",result.getAdjustAmount());
                    detail.put("tradeId",result.getId());
                    sendDayDetailList.add(detail);
                }

                map.put("sendDayDetailList",sendDayDetailList);


                break;
        }

        return Response.getSuccess(map);
    }

    @Override
    public Response shopBonusRule(String shopId, String groupId) throws ApplicationException {
        Map<String, Object> map = new HashMap<String, Object>();
        if (Tools.isEmpty(groupId)) {
            throw new ApplicationException(Rescode.FAIL, "groupId 不能为空！");
        }
        //发放 判断有没有设置行业规则
//		int count = bonusSendRuleMapper.queryBonusSendRuleCount(Long.parseLong(groupId));
        //有设置行业规则
        List<Map<String, Object>> sendRuleList = new ArrayList<Map<String, Object>>();
//		if(count>0){
//			List<BonusSendRule> bonusSendRuleList =bonusSendRuleMapper.queryBonusSendRuleList(Long.parseLong(groupId));
//			for (BonusSendRule bonusSendRule : bonusSendRuleList) {
//				Map<String, Object> sendruleMap = new HashMap<String, Object>();
//				//写死 告诉前端 方便处理 这是已经设置行业规则的
//				sendruleMap.put("type",1);
//				sendruleMap.put("industryName",bonusSendRule.getIndustryName());
//				sendruleMap.put("send_day_max",bonusSendRule.getSendDayMax());
//				sendruleMap.put("send_single_max",bonusSendRule.getSendSingleMax());
//				sendruleMap.put("send_day_count",bonusSendRule.getSendDayCount());
//				sendruleMap.put("send_accounted_time",bonusSendRule.getSendAccountedTime());
//				sendruleMap.put("send_time_type",bonusSendRule.getSendTimeType());//发放时间leixing
//				sendRuleList.add(sendruleMap);
//			}
//			if (sendRuleList.size() > 0) {
//				map.put("bonusSendRule_List", sendRuleList);
//			}
//		}else{
        BonusSendRule bonusSendRule =bonusSendRuleMapper.queryBonusSendRule(Long.parseLong(groupId));
        Map<String, Object> sendruleMap2 = new HashMap<String, Object>();
        sendruleMap2.put("type",0);
        sendruleMap2.put("send_day_max",bonusSendRule.getSendDayMax());
        sendruleMap2.put("send_single_max",bonusSendRule.getSendSingleMax());
        sendruleMap2.put("send_day_count",bonusSendRule.getSendDayCount());
        sendruleMap2.put("send_accounted_time",bonusSendRule.getSendAccountedTime());
        sendruleMap2.put("send_time_type",bonusSendRule.getSendTimeType());//发放时间leixing
        sendRuleList.add(sendruleMap2);
        if (sendRuleList.size() > 0) {
            map.put("bonusSendRule_List", sendRuleList);
        }
//		}

        //核销
        //发放 判断门店有没有设置行业规则
        List<Map<String, Object>> veriftyRuleList = new ArrayList<Map<String, Object>>();
//		int count2 = bonusVerifyRuleMapper.queryBonusVeriftyRuleByShopId(Long.parseLong(groupId),Long.parseLong(shopId));
        BonusVerifyRule bonusVerifyRule2 =bonusVerifyRuleMapper.selectBonusVeriftyRuleByShopId(Long.parseLong(shopId),Long.parseLong(groupId));
		if(bonusVerifyRule2 != null){

//            BonusRuleOutDTO bonusVerifyRule =bonusVerifyRuleMapper.queryShopBonusVerifyRule(Long.parseLong(groupId));

				Map<String, Object> veriftyruleMap = new HashMap<String, Object>();
				//写死 告诉前端 方便处理 这是已经设置行业规则的
				veriftyruleMap.put("type",1);
				veriftyruleMap.put("verify_rate",bonusVerifyRule2.getVerifyRate());
				veriftyruleMap.put("verify_single_min_type",bonusVerifyRule2.getVerifySingleMinType());
				veriftyruleMap.put("verify_single_min",bonusVerifyRule2.getVerifySingleMin());
				veriftyruleMap.put("verify_single_max_type",bonusVerifyRule2.getVerifySingleMinType());
				veriftyruleMap.put("verify_single_max",bonusVerifyRule2.getVerifySingleMax());
				veriftyruleMap.put("verify_day_count",bonusVerifyRule2.getVerifyDayCount());
				veriftyruleMap.put("verify_day_sum",bonusVerifyRule2.getVerifyDaySum());
                veriftyruleMap.put("verify_time_type",bonusVerifyRule2.getVerifyTimeType());
//				if(bonusVerifyRule.getVerifyTimeType()==1){
//					veriftyruleMap.put("verify_time_from",bonusVerifyRule.getVerifyTimeFrom1());
//					veriftyruleMap.put("verify_time_to",bonusVerifyRule.getVerifyTimeTo1());
//				}else if(bonusVerifyRule.getVerifyTimeType()==2){
//					veriftyruleMap.put("verify_time_from",bonusVerifyRule.getVerifyTimeFrom2());
//					veriftyruleMap.put("verify_time_to",bonusVerifyRule.getVerifyTimeTo2());
//				}else{
//					veriftyruleMap.put("verify_time_from",bonusVerifyRule.getVerifyTimeFrom3());
//					veriftyruleMap.put("verify_time_to",bonusVerifyRule.getVerifyTimeTo3());
//				}
				veriftyRuleList.add(veriftyruleMap);

			if (veriftyRuleList.size() > 0) {
				map.put("bonusVerifyRule_List", veriftyRuleList);
			}
		}else{
            BonusVerifyRule bonusVerifyRule =bonusVerifyRuleMapper.queryBonusVeriftyRule(Long.parseLong(groupId));
            Map<String, Object> veriftyruleMap2 = new HashMap<String, Object>();
            veriftyruleMap2.put("type",0);
            veriftyruleMap2.put("verify_rate",bonusVerifyRule.getVerifyRate());
            veriftyruleMap2.put("verify_single_min_type",bonusVerifyRule.getVerifySingleMinType());
            veriftyruleMap2.put("verify_single_min",bonusVerifyRule.getVerifySingleMin());
            veriftyruleMap2.put("verify_single_max_type",bonusVerifyRule.getVerifySingleMaxType());
            veriftyruleMap2.put("verify_single_max",bonusVerifyRule.getVerifySingleMax());
            veriftyruleMap2.put("verify_time_type",bonusVerifyRule.getVerifyTimeType());
            veriftyruleMap2.put("verify_day_count",bonusVerifyRule.getVerifyDayCount());
            veriftyruleMap2.put("verify_day_sum",bonusVerifyRule.getVerifyDaySum());
            veriftyRuleList.add(veriftyruleMap2);
            if (veriftyRuleList.size() > 0) {
                map.put("bonusVerifyRule_List", veriftyRuleList);
            }
		}

        return Response.getSuccess(map);
    }

    @Override
    public Response profitManage(String shopId) throws ApplicationException {
        Map<String, Object> map = new HashMap<>();

        //本月预估收益
        Profit profit = profitMapper.selectThisShopProfit(Long.parseLong(shopId));
        if(profit!=null){
           map.put("thisMonthProfit",profit.getShopProfit());
        }else{
            map.put("thisMonthProfit",0);
        }
        //上月收益
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date); // 设置为当前时间
        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
        date = calendar.getTime();
        System.out.println(dateFormat.format(date));
        String date1 = dateFormat.format(date);
        date1 = date1.substring(0, date1.length() - 2);
        String newDate = date1.substring(0, 4) + "年" + date1.substring(4, date1.length()) + '月';
        map.put("lastTime",newDate);
//
//        ProfitShopMonth profitShopMonth = profitShopMonthMapper.queryShopMonthProfit(Long.parseLong(shopId),date1);
//        if(profitShopMonth!=null){
//            map.put("lastMonthProfit",profitShopMonth.getProfit());
//        }else{
//            map.put("lastMonthProfit",0);
//        }

        //上月收益
        Profit profit2 = profitMapper.selectLastShopProfit(Long.parseLong(shopId));
        map.put("lastMonthProfit",profit2.getShopProfit());

        //上月发展会员消费次数 上月会员消费金额
        TradeOffline tradeOffline = tradeOfflineMapper.queryShopLastMonthProfit(Long.parseLong(shopId));
        map.put("lastCustomerCount",tradeOffline.getNumber());
        map.put("lastCustomerAmount",tradeOffline.getRealAmount());

        //累计收益
        Profit profit1 = profitMapper.queryShopAllProfit(Long.parseLong(shopId));
        map.put("allGetAmount",profit1.getShopProfit());

        //门店发展人数累计
        Member member = memberMapper.queryShopDevMemberCount(Long.parseLong(shopId));
        map.put("devMemberCount",member.getAddUserCount());

        return Response.getSuccess(map);
    }

    @Override
    public Response shopMonthDetailList(String shopId, Integer pageNo, Integer pageSize) throws ApplicationException {
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> param = new HashMap<>();
        List<Map<String, Object>> shopProfitList = new ArrayList<Map<String, Object>>();
        //累计收益
        Profit profit1 = profitMapper.queryShopAllProfit(Long.parseLong(shopId));
        map.put("allGetAmount",profit1.getShopProfit());

        param.put("shopId",shopId);
        param.put("start", pageSize * (pageNo - 1));
        param.put("limit", pageSize);

        List<Profit> profitList = profitMapper.queryMonthShopProfitData(param);
        for(Profit profit:profitList){
            Map<String, Object> detail = new HashMap<>();
            detail.put("statisDate",DateUtil.fomatDate(profit.getGmtCreate(),sdfMonth));
            detail.put("profitAmount",profit.getShopProfit());

            Date statisDate = profit.getGmtCreate();
            int number = profitMapper.queryMonthProfitCount(Long.parseLong(shopId),statisDate);
            detail.put("count",number);
            shopProfitList.add(detail);
        }
        if(shopProfitList.size()>0){
            map.put("shopProfitList",shopProfitList);
        }
/*
        int count=  profitShopMonthMapper.queryShopProfitDataCount(Long.parseLong(shopId));
        if(count ==0){
            map.put("shopProfitList", shopProfitList);
            return Response.getSuccess(map);
        }
        param.put("start", pageSize * (pageNo - 1));
        param.put("limit", pageSize);

        List<ProfitShopMonth> profitShopMonthList = profitShopMonthMapper.queryShopProfitData(param);
        for(ProfitShopMonth profitShopMonth:profitShopMonthList){
            Map<String, Object> detail = new HashMap<>();
            detail.put("statisDate",profitShopMonth.getStatisDate());
            detail.put("profitAmount",profitShopMonth.getProfit());

            String statisDate = profitShopMonth.getStatisDate().substring(0,4)+"-"+profitShopMonth.getStatisDate().substring(4,6)+"-01";
            int number = profitMapper.queryMonthProfitCount(Long.parseLong(shopId),statisDate);
            detail.put("count",number);
            shopProfitList.add(detail);
        }
        if(shopProfitList.size()>0){
            map.put("shopProfitList",shopProfitList);
        }
*/


        return Response.getSuccess(map);
    }

    @Override
    public Response profitDayList(String shopId, String statisDate, Integer pageNo, Integer pageSize) throws ApplicationException {
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> param = new HashMap<>();
        List<Map<String, Object>> profitDetailList = new ArrayList<>();
        param.put("shopId",shopId);
        map.put("monthDate",statisDate);

        statisDate= statisDate+"-01";
        Profit result = profitMapper.queryShopProfitDetail(Long.parseLong(shopId),statisDate);
        if(result !=null){

            map.put("profitAmount",result.getShopProfit());
        }else{
            map.put("profitAmount",0);
        }


        Date date = DateUtil.fomatDate(statisDate);
        param.put("statisDate",statisDate);

        int number = profitMapper.queryMonthProfitCount(Long.parseLong(shopId),date);
        map.put("number",number);

        int count = profitMapper.queryShopDevMemberTradeCount(param);
        if(count==0){
            map.put("profitDetailList", profitDetailList);
            return Response.getSuccess(map);
        }

        param.put("start", pageSize * (pageNo - 1));
        param.put("limit", pageSize);


        List<Profit> profitList = profitMapper.queryShopDevMemberTradeList(param);
        for(Profit profit :profitList){
            Map<String, Object> detail = new HashMap<>();

            detail.put("gmtCreate",profit.getGmtCreate());
            if(profit.getMemberName() !=null){
                detail.put("name",profit.getMemberName());
            }else{
                detail.put("name","");
            }
            if(profit.getMemberId() !=null){
                detail.put("memberId",profit.getMemberId());
            }else{
                detail.put("memberId","");
            }

            detail.put("tradeId",profit.getOrderId());
            detail.put("tradeAmount",profit.getRealAmount());
            detail.put("payType", BizEnum.PaymentType.fromType(profit.getPayType()).getName());
            profitDetailList.add(detail);
        }
        if(profitDetailList.size()>0){
            map.put("profitDetailList",profitDetailList);
        }


        return Response.getSuccess(map);
    }


}
